<%@ page import="weaver.general.Util" %>
<%@ page import="java.util.Map" %>
<%@ page import="java.util.LinkedHashMap" %>
<%@ page import="java.util.Date" %>
<%@ page import="java.io.PrintWriter" %>
<jsp:useBean id="rs" class="weaver.conn.RecordSet" scope="page" />
<%@ page language="java" contentType="text/html; charset=UTF-8" %>


<%
        //获取当前用户id
        String loginid = null;
        Cookie[] cookies = request.getCookies();
        for (Cookie cookie:
            cookies) {
            if ("loginidweaver".equals(cookie.getName())){
                loginid = cookie.getValue();
            }
        }
        if (loginid == null) {
            response.getWriter().write("loginid is null");
            return;
        }


        //查询当前服务器时间是否存在周别

        //查询本周是否需要填写月报
       String sql = "select CONVERT(varchar(100), GETDATE(), 23) as nowDate,datepart(weekday, getdate())-1 as nowWeekday,id,zb,isyb,sfqk from formtable_main_3 where qsrq <= (select CONVERT(varchar(100), GETDATE(), 23)) and jsrq >= (select CONVERT(varchar(100), GETDATE(), 23))";
       rs.execute(sql);
       if(rs.next()){
           String zbid =  rs.getString("id");
           String isyb =  rs.getString("isyb");
           String sfqk = rs.getString("sfqk");
           String nowDate = rs.getString("nowDate");
           String nowWeekday = rs.getString("nowWeekday");
           //需要填写月报
           if("1".equals(isyb)){
            //判断本周别是否已经填写过月报
            sql = "select * from uf_jbzxxx main,uf_jbzxxx_dt1 dt1 where main.id = dt1.mainid and modedatacreater = '"+loginid+"' and zb = '"+zbid+"' order by modedatacreatedate,modedatacreatetime desc";
             rs.execute(sql);
             if(rs.next()){
                PrintWriter writer = response.getWriter();
                writer.write("本周已经填写过月报了！");
             }else{
                 if("0".equals(sfqk)){
                   String is123 = ("1".equals(nowWeekday)||"2".equals(nowWeekday)||"3".equals(nowWeekday))?"true":"false";
                    if("false"==is123){
                        PrintWriter writer = response.getWriter();
                        writer.write("当前选中周别必须为周别周一周二周三提交月报");
                    }
                 }
                
             }

               
           }else{
               PrintWriter writer = response.getWriter();
               writer.write("当前周别不允许填写月报！");
           }

       }
%>